import React, { useState, useEffect } from "react";
import { Select, Tooltip } from "antd"; // 假设你正在使用Ant Design的Select组件
import { queryTakeUserList } from "./service";
import { isEmpty } from "lodash";

const { Option } = Select;

const ReceivingSelect = ({ value, onChange }) => {
	const [receivingList, setReceivingList] = useState([]);

	useEffect(() => {
		handleUserList();
	}, []);
	const handleUserList = async username => {
		const { data = [], success } = await queryTakeUserList({ username, current: 1, size: 200 }); // 假设getWarehouseList是一个获取仓库列表的异步函数
		if (success) {
			console.log(data, "dddddddddddddddd");
			setReceivingList(data);
		}
	};
	const renderSubUser = item => {
		if (item.name) {
			if (item.account) {
				return item.name + "(" + item.account + ")";
			} else {
				return item.name;
			}
		} else {
			return "";
		}
	};
	const optionUserList =
		!isEmpty(receivingList) &&
		receivingList.map(item => (
			<Option value={item.id} key={item.id}>
				<Tooltip title={renderSubUser(item)}>{renderSubUser(item)}</Tooltip>
			</Option>
		));
	return (
		// <Select showSearch placeholder="拿货员" filterOption={false} onSearch={handleUserList} allowClear >
		// 	{optionUserList}
		// </Select>
		<Select showSearch placeholder="拿货员" value={value} filterOption={false} onChange={onChange} onSearch={handleUserList}>
			{receivingList.map(function (item) {
				return (
					<Option value={item.name} key={item.id}>
						{item.name}
					</Option>
				);
			})}
		</Select>
	);
};

export default ReceivingSelect;
